package com.cangxuan.manage.service.impl;

import com.cangxuan.manage.dao.IssuerDao;
import com.cangxuan.manage.entity.Issuer;
import com.cangxuan.manage.exception.ServiceException;
import com.cangxuan.manage.service.IIssuerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IssuerServiceImpl implements IIssuerService {
    IssuerDao issuerDao;

    @Autowired
    public void setIssuerDao(IssuerDao issuerDao) {
        this.issuerDao = issuerDao;
    }


    @Override
    public List<Issuer> getIssuer() {
       return issuerDao.getIssuer();
    }

    @Override
    public boolean save(Issuer issuer) {
        return issuer.getId() == 0 ? issuerDao.insert(issuer) > 0 : issuerDao.update(issuer) > 0;
    }

    @Override
    public boolean delete(int id) {
        if (issuerDao.selectCount(id) > 0) {
            throw new ServiceException(402, "仍有商品绑定该系列,无法删除");
        }
        if (issuerDao.delete(id) == 0) {
            throw new ServiceException(402, "删除失败，ID不存在");
        }
        return true;
    }


}

